package Demo01;


import javax.swing.*;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        LinkedList<Character> list = new LinkedList();
        list.add('a');
        list.add('b');
        list.add('c');
        list.add('d');
        //直接打印
        System.out.println(list);
        //foreach遍历
        for (Character c: list) {
            System.out.print(c+" ");
        }
        System.out.println();
        //for循环遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        //迭代器正向遍历
        ListIterator<Character> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        //迭代器反向遍历
        while (it.hasPrevious()) {
            System.out.print(it.previous()+" ");
        }

    }
    public static void main02(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(0,6);

        LinkedList<Number> list1 = new LinkedList<>();
        list1.add(2.3);
        list1.add(2);
        list1.addAll(list);

        for (int i = 0; i < list1.size(); i++) {
            System.out.print(list1.get(i)+" ");
        }
    }
    public static void main01(String[] args) {
        List<Integer> list = new LinkedList<>();

        List<Double> list1 = new LinkedList<>();
        list1.add(1.1);
        list1.add(2.1);

        List<Number> list2 = new LinkedList<>(list1);
        list2.add(3);
        list2.add(4);
        System.out.println(list2);
    }
}
